<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增商家任务')" />
    <th:block th:include="include :: select2-css"/>
    <th:block th:include="include :: bootstrap-select-css"/>
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-task-add">
            <div class="col-md-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label">商家名称：</label>
                    <div class="col-sm-8">
                        <select id="mercId" class="form-control" >
                            <option th:each="merc:${mercList}" th:value="${merc.id}" th:text="${merc.mercName}"></option>
                        </select>
                    </div>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">店铺名称：</label>
                <div class="col-sm-8">
                    <input name="storeName" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">产品单价(元)：</label>
                <div class="col-sm-8">
                    <input name="productAmount" class="form-control" type="number" required>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">产品链接：</label>
                <div class="col-sm-8">
                    <input name="productLink" id="productLink" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">总任务总数：</label>
                <div class="col-sm-8">
                    <input name="taskAllCounts" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">备注信息：</label>
                <div class="col-sm-8">
                    <textarea name="remark" class="form-control" ></textarea>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: select2-js"/>
    <th:block th:include="include :: bootstrap-select-js"/>
    <script th:inline="javascript">
        var prefix = ctx + "system/task"
        $("#form-task-add").validate({
            onkeyup: false,
            rules:{
                productLink:{
                    minlength: 2,
                    maxlength: 1000,
                    remote: {
                        url: prefix + "/checkProductLinkUnique",
                        type: "post",
                        dataType: "json",
                        data: {
                            "productLink": function () {
                                return $.common.trim($("#productLink").val());
                            }
                        }
                    }
                }
            },
            messages:{
                "productLink": {
                    remote: "产品链接已存在,不能重复添加"
                },
            },
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {
                var data = $("#form-task-add").serializeArray();
                var mercId = $.form.selectSelects("mercId");
                data.push({"name": "mercId", "value": mercId});
                $.operate.save(prefix + "/add", data);
            }
        }
    </script>
</body>
</html>